package cn.yujiago.activiti.service.impl;

import cn.yujiago.activiti.constant.MessageConstant;
import cn.yujiago.activiti.dto.ResponseEntity;
import cn.yujiago.activiti.entity.User;
import cn.yujiago.activiti.mapper.UserMapper;
import cn.yujiago.activiti.service.UserService;
import cn.yujiago.activiti.util.SessionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public ResponseEntity login(User user) {

        User loginUser = userMapper.selectUserByUsernamePassword(user.getUsername(), user.getPassword());

        if(loginUser != null){
            SessionUtils.set(loginUser);
            return ResponseEntity.build(200, MessageConstant.LOGIN_SUCCESS);
        }else{
            return ResponseEntity.build(404, MessageConstant.LOGIN_FAIL);
        }

    }
}
